<?php
my_component_load('testing' , false);
my_component_load('paging' , false); 
my_component_load('data_setting', false);
my_component_load('jabatan' );
$task = isset($_GET['task']) ? $_GET['task'] : ""; 
$id = isset( $_GET['id'] ) ? $_GET['id']:  0;
$sk_id= isset( $_GET['sk_id'] ) ? $_GET['sk_id']:  0;
$parent_id = isset( $_GET['parent_id'] ) ? $_GET['parent_id']:  0;
//$level_id = isset( $_GET['level_id'] ) ? $_GET['level_id']:  1;
$modulname = "Admin _BN_ Konfigurasi Data";
$pagename ='';
if($_SERVER['REQUEST_METHOD'] == "POST" ):
	switch($task){
		case   "edit_sk_page" :
			$validatepost = form_sk_validate($id);
			if($validatepost){
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .=form_sk($id);
				generate_my_web($content,"","plain.php");
				exit; 
			}else{
				submit_sk($id);
				$content =  "Updated";
				generate_my_web($content,"","plain.php");
				exit;
			}	
			break;	
		case   "devisicreate" :
			$validatepost = form_devisi_validate();
			if($validatepost){
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .=form_jabatan_create($sk_id, $parent_id , $id);
				generate_my_web($content,"","plain.php");
				exit; 
			}else{
				$jabatan_id = form_jabatan_submit($sk_id, $parent_id , $id);
				/*
				$datajabatan = get_departemen_id_and_direktorat_id( $level_id,$parent_id);
				$newjabatandatas = array(
					'departemen_id'=>my_type_data_int($datajabatan['departemen']),
					'direktorat_id'=>my_type_data_int($datajabatan['direktorat']),
				);
				my_update_record('jabatan','jabatan_id',$jabatan_id,$newjabatandatas);
				*/
				$content =  "Updated";
				generate_my_web($content,"","plain.php");
				exit;
			 }
			break;
		case   "jabatancreate" :
			form_jabatan_submit();
			$content =  "Updated";
			generate_my_web($content,"","plain.php");
			exit;
		break;
	}

else: 	
	if($task == "list_jabatan"){
		load_facebox_script();
		$view =  list_jabatan($sk_id,$parent_id); 
		$href='index.php?com='.$_GET['com'].'&task=editdevisi&sk_id='.$sk_id.
			'&parent_id='.$parent_id;
	}elseif($task == "editdevisi"){
		$title= ($id > '0' ) ?  "Perubahan data jabatan" : "Tambah data jabatan";
		facebox_page('index.php?com='.$_GET['com'].'&task=devisicreate
		&sk_id='.$sk_id.'
		&parent_id='.$parent_id.'&id='.$id , $title , 400	); 
	}elseif($task == "devisicreate"){ 
		$content  = form_jabatan_create($sk_id,$parent_id , $id );
		generate_my_web($content,"","plain.php");
		exit; 
	}elseif($task == 'delete_jabatan'){ // DELETE ITEM	
		remove_jabatan($id);
		my_direct('index.php?com='.$_GET['com']);
			
	}elseif($task == "edit_sk"){ 
		$pagename = ($id > 0 ) ? "Perubahan Data" : "Tambah Data";
		facebox_page('index.php?com='.$_GET['com'].'&task=edit_sk_page&id='.$id , $pagename , 240	);
	}elseif($task == "edit_sk_page"){
		$content = form_sk($id);
		generate_my_web($content, '' ,"plain.php");
		exit;
	}elseif($task == 'deletesk'){ 
		delete_sk($id);
		my_direct('index.php?com='.$_GET['com']);		
	}else{
		$pagename = "Daftar SK Struktur";
		load_facebox_script();
		$view =  list_sk() ; 
		$href='index.php?com='.$_GET['com'].'&task=edit_sk';
		
	}
endif; 
$content = spliter_browser( $view , $pagename ,$href);
generate_my_web($content, $modulname." _BN_ Setting Struktur" );
?>